import { createRouter, createWebHistory } from 'vue-router';
import LoginPage from './page/LoginPage.vue';
import HomePage from './page/HomePage.vue';
import BannerList from './components/home/homeMain/banner/BannerList.vue';
import Textarea from './components/home/homeMain/textarea/Textarea.vue';
import Echarts from './components/home/homeMain/echarts/Echarts.vue'
import { ElMessage } from 'element-plus';
const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: '/',
            alias: '/LoginPage',
            component: LoginPage
        },
        {
            path: '/HomePage',
            component: HomePage,
            // beforeEnter(to, from) {
            //     const token = localStorage.getItem('token')
            //     const adminname = localStorage.getItem('adminname')
            //     if (!token || !adminname) {
            //         ElMessage.warning('未登录')
            //         return '/'
            //     }
            // },
            children: [
                {
                    path: 'MainImages',
                    component: BannerList
                },
                {
                    path: 'Textarea',
                    component: Textarea
                },
                {
                    path: 'Echarts',
                    component: Echarts
                }
            ]
        }
    ]
})
router.beforeEach((to, from) => {
    if (to.path !== '/') {
        const token = localStorage.getItem('token');
        const adminname = localStorage.getItem('adminname');
        if (!token || !adminname) {
            ElMessage.warning('未登录')
            return '/'
        }
    }
})
export default router